package com.kky.pp.adapter

import android.content.Context
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.custom.base.config.BaseConfig
import com.kky.pp.R
import com.kky.pp.entity.MemberSubscribeEntity
import com.custom.base.util.SDViewUtil
import com.youth.banner.adapter.BannerAdapter
import io.rong.imkit.SpName

class PageBuyMemberAdapter(
    val mActivity: Context,
    val data: List<MemberSubscribeEntity.Data.Subscriptions>
) : BannerAdapter<MemberSubscribeEntity.Data.Subscriptions, PageBuyMemberAdapter.BannerViewHolder>(data) {
    //创建ViewHolder，可以用viewType这个字段来区分不同的ViewHolder
    override fun onCreateHolder(parent: ViewGroup, viewType: Int): BannerViewHolder {
        val view = SDViewUtil.getRId(parent.context, R.layout.item_buy_member_page)
        //注意，必须设置为match_parent，这个是viewpager2强制要求的
        view.layoutParams = ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT
        )
        return BannerViewHolder(view)
    }

    override fun onBindView(holder: BannerViewHolder?, bean: MemberSubscribeEntity.Data.Subscriptions, position: Int, size: Int) {
        holder?.apply {
            val imgTop = view.findViewById<ImageView>(R.id.imgViewItemBuyVipTop)
            val itemTitle = view.findViewById<TextView>(R.id.txtItemBuyVipTitle)
            val itemContent = view.findViewById<TextView>(R.id.txtItemBuyVipContent)
            val ppvVisibility = BaseConfig.getInstance.getBoolean(SpName.privatePhotoShowUnableFlag, false)
            if (ppvVisibility){
                when(position){
                    0->{
                        imgTop.setImageResource(R.mipmap.icon_popup_unlimited_match)
                    }
                    1->{
                        imgTop.setImageResource(R.mipmap.icon_popup_see_who_likes_you)
                    }
                    2->{
                        imgTop.setImageResource(R.mipmap.icon_popup_flash_chat)
                    }
                    3->{
                        imgTop.setImageResource(R.mipmap.icon_popup_release_private_album)
                    }
                }
            }else{
                when(position){
                    0->{
                        imgTop.setImageResource(R.mipmap.icon_popup_unlimited_match)
                    }
                    1->{
                        imgTop.setImageResource(R.mipmap.icon_popup_see_who_likes_you)
                    }
                    2->{
                        imgTop.setImageResource(R.mipmap.icon_popup_flash_chat)
                    }
                    3->{
                        imgTop.setImageResource(R.mipmap.icon_popup_private_photos)
                    }
                    4->{
                        imgTop.setImageResource(R.mipmap.icon_popup_private_videos)
                    }
                    5->{
                        imgTop.setImageResource(R.mipmap.icon_popup_release_private_album)
                    }
                    6->{
                        imgTop.setImageResource(R.mipmap.icon_no_member_album)
                    }
                }
            }
            when(position){
                0->{
                    imgTop.setImageResource(R.mipmap.icon_popup_unlimited_match)
                }
                1->{
                    imgTop.setImageResource(R.mipmap.icon_popup_see_who_likes_you)
                }
                2->{
                    imgTop.setImageResource(R.mipmap.icon_popup_flash_chat)
                }
                3->{
                    imgTop.setImageResource(R.mipmap.icon_popup_private_photos)
                }
                4->{
                    imgTop.setImageResource(R.mipmap.icon_popup_private_videos)
                }
                5->{
                    imgTop.setImageResource(R.mipmap.icon_popup_release_private_album)
                }
                6->{
                    imgTop.setImageResource(R.mipmap.icon_no_member_album)
                }
            }

            itemTitle.text=bean.tip
            itemContent.text=bean.content
        }
    }

    inner class BannerViewHolder(var view: View) : RecyclerView.ViewHolder(
        view
    )
}